import { Provide, Inject } from '@midwayjs/core';
import { UserService } from '../service/user.service';
import { uploadDao } from '../dao/upload.dao';
import * as Minio from 'minio';
@Provide()
export class UploadSerivce {
  @Inject()
  userService: UserService;
  @Inject()
  uploadDao: uploadDao;

  //minio配置
  minioClient = new Minio.Client({
    endPoint: '1',
    useSSL: false,
    port: 1,
    accessKey: '1',
    secretKey: '1',
  });

  //存储文件
  async upload(files: Array<any>, fields: Record<string, string>) {
    const filename = files[0].filename;
    console.log('filename:', filename); // 检查是否为 undefined
    console.log('files[0]:', files[0]); // 检查 files[0] 是否存在
    await this.minioClient.fPutObject('xierfloat', filename, files[0].data);
    const url = `1`;
    return { url };
  }
}
